import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Req,
  Query,
} from '@nestjs/common';
import { CommentService } from './comment.service';
import { CreateCommentDto } from './dto/create-comment.dto';
import { ApiOperation } from '@nestjs/swagger';
import { PaginationDto } from './dto/pagination.dto';

@Controller('comment')
export class CommentController {
  constructor(private readonly commentService: CommentService) {}

  @Post()
  @ApiOperation({ summary: '新增评论' })
  async create(@Body() dto: CreateCommentDto, @Req() req) {
    return this.commentService.createComment(dto, req.user.id);
  }

  @Get('/video/:videoId')
  @ApiOperation({ summary: '获取视频下的评论' })
  async getVideoComments(
    @Param('videoId') videoId: string,
    @Query('page') page: number = 1,
    @Query('limit') limit: number = 10,
  ) {
    return this.commentService.getCommentsByVideo(
      parseInt(videoId),
      { page, limit },
    );
  }

  @Delete(':id')
  @ApiOperation({ summary: '删除评论' })
  async delete(@Param('id') id: string, @Req() req) {
    return this.commentService.deleteComment(parseInt(id), req.user.id);
  }
}
